import { RouteRecordRaw } from "vue-router";
import noAuthView from "@/views/NoAuthView.vue";
import ACCESS_ENUM from "@/access/accessEnum";
import UserLoginView from "@/views/user/UserLoginView.vue";
import UserRegisterView from "@/views/user/UserRegisterView.vue";
import UserLayout from "@/layouts/UserLayout.vue";
import AddQuestionView from "@/views/question/AddQuestionView.vue";
import ManageQuestionView from "@/views/question/ManageQuestionView.vue";
import SearchQuestionView from "@/views/question/SearchQuestionView.vue";
import DoQuestionView from "@/views/question/DoQuestionView.vue";
import SearchQuestionSubmitView from "@/views/question/SearchQuestionSubmitView.vue";

export const routes: Array<RouteRecordRaw> = [
  {
    path: "/user",
    name: "用户",
    component: UserLayout,
    children: [
      {
        path: "/user/login",
        name: "用户登录",
        component: UserLoginView,
      },
      {
        path: "/user/register",
        name: "用户注册",
        component: UserRegisterView,
      },
    ],
    meta: {
      hideInMenu: true,
    },
  },
  {
    path: "/",
    name: "主页",
    component: SearchQuestionView,
  },
  {
    path: "/questions",
    name: "题目列表",
    component: SearchQuestionView,
  },
  {
    path: "/question_submit",
    name: "题目提交列表",
    component: SearchQuestionSubmitView,
  },
  {
    path: "/add/question",
    name: "创建题目",
    component: AddQuestionView,
    // 权限判断
    meta: {
      access: ACCESS_ENUM.USER,
    },
  },
  {
    path: "/manage/question",
    name: "管理题目",
    component: ManageQuestionView,
    // 权限判断
    meta: {
      access: ACCESS_ENUM.ADMIN,
    },
  },
  {
    path: "/update/question",
    name: "修改题目",
    component: AddQuestionView,
    // 权限判断
    meta: {
      hideInMenu: true,
      access: ACCESS_ENUM.USER,
    },
  },
  {
    path: `/view/question/:id`,
    name: "在线做题",
    component: DoQuestionView,
    // 这里的路径使用动态路由参数，为了在页面中可以获取到这个参数；需要将props设置为true
    props: true,
    // 权限判断
    meta: {
      hideInMenu: true,
      access: ACCESS_ENUM.USER,
    },
  },
  {
    path: "/noauth",
    name: "无权限",
    component: noAuthView,
    meta: {
      hideInMenu: true,
    },
  },
];
